﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using System.Web.Script.Serialization;
using System.Web.Helpers;
using System.Data;

public partial class Services_Services : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }


    [WebMethod(true)]
    public static bool IsValidPO(string po)
    {
        bool ret = false;
        string sql = "SELECT count(1) FROM tbl_purchase_order where LOWER(PURCHASE_ORDER_NO)=@PURCHASE_ORDER_NO";
        MySqlCommand cmd = new MySqlCommand(sql);
        cmd.Parameters.AddWithValue("@PURCHASE_ORDER_NO", po.ToLower());
        if (Convert.ToInt32(DBUtil.ExecuteScalar(cmd)) > 0)
            ret = true;
        else
            ret = false;

        return ret ;
    }


    [WebMethod(true)]
    public static bool save_leco_carbon(List<tbl_qcsicomill_leco_carbon> data)
    {
        bool ret = false;
        BLL_tbl_qcsicomill_leco_carbon bll = new BLL_tbl_qcsicomill_leco_carbon();
        ret=bll.insert(data);

        return ret;
    }

    [WebMethod(true)]
    public static bool update_leco_carbon(List<tbl_qcsicomill_leco_carbon> data)
    {
        bool ret = false;
        BLL_tbl_qcsicomill_leco_carbon bll = new BLL_tbl_qcsicomill_leco_carbon();
        ret = bll.update(data);

        return ret;
    }

    [WebMethod(true)]
    public static bool save_xrf(List<tbl_qcsicomill_xrf> data)
    {
        bool ret = false;
        BLL_tbl_qcsicomill_xrf bll = new BLL_tbl_qcsicomill_xrf();
        ret = bll.insert(data);

        return ret;
    }

    [WebMethod(true)]
    public static bool update_xrf(List<tbl_qcsicomill_xrf> data)
    {
        bool ret = false;
        BLL_tbl_qcsicomill_xrf bll = new BLL_tbl_qcsicomill_xrf();
        ret = bll.update(data);

        return ret;
    }

    [WebMethod(true)]
    public static bool save_particleSize(List<tbl_qcsicomill_particlesize> data)
    {
        bool ret = false;
        BLL_tbl_qcsicomill_particlesize bll = new BLL_tbl_qcsicomill_particlesize();
        ret = bll.insert(data);

        return ret;
    }

    [WebMethod(true)]
    public static bool update_particleSize(List<tbl_qcsicomill_particlesize> data)
    {
        bool ret = false;
        BLL_tbl_qcsicomill_particlesize bll = new BLL_tbl_qcsicomill_particlesize();
        ret = bll.update(data);

        return ret;
    }

    [WebMethod(true)]
    public static bool save_ph(List<tbl_qcsicomill_ph> data)
    {
        bool ret = false;
        BLL_tbl_qcsicomill_ph bll = new BLL_tbl_qcsicomill_ph();
        ret = bll.insert(data);

        return ret;
    }

    [WebMethod(true)]
    public static bool update_ph(List<tbl_qcsicomill_ph> data)
    {
        bool ret = false;
        BLL_tbl_qcsicomill_ph bll = new BLL_tbl_qcsicomill_ph();
        ret = bll.update(data);

        return ret;
    }

    [WebMethod(true)]
    public static bool save_ssa(List<tbl_qcsicomill_ssa> data)
    {
        bool ret = false;
        BLL_tbl_qcsicomill_ssa bll = new BLL_tbl_qcsicomill_ssa();
        ret = bll.insert(data);

        return ret;
    }

    [WebMethod(true)]
    public static bool update_ssa(List<tbl_qcsicomill_ssa> data)
    {
        bool ret = false;
        BLL_tbl_qcsicomill_ssa bll = new BLL_tbl_qcsicomill_ssa();
        ret = bll.update(data);

        return ret;
    }

    [WebMethod(true)]
    public static bool save_635mess(List<tbl_qcsicomill_635mess> data)
    {
        bool ret = false;
        BLL_tbl_qcsicomill_635mess bll = new BLL_tbl_qcsicomill_635mess();
        ret = bll.insert(data);

        return ret;
    }

    [WebMethod(true)]
    public static bool update_635mess(List<tbl_qcsicomill_635mess> data)
    {
        bool ret = false;
        BLL_tbl_qcsicomill_635mess bll = new BLL_tbl_qcsicomill_635mess();
        ret = bll.update(data);

        return ret;
    }

    [WebMethod(true)]
    public static string getNextWorkOrderNumber(string input)
    {
        string ret = "";
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = @"select 
                    CONCAT(DATE_FORMAT(NOW(),'%y%m%d') , '-' , USER_CODE, '-',
                    (select count(*) + 1 from tbl_sicomill_work_order where tbl_sicomill_work_order.PO_Number=@PO_Number)
                    ) as 'WONumber'
                    FROM tbl_purchase_order where PURCHASE_ORDER_NO=@PO_Number;";
        cmd.Parameters.AddWithValue("@PO_Number", input);
        ret=DBUtil.ExecuteScalar(cmd).ToString();
        return ret;
    }


    [WebMethod(true)]
    public static bool save_sicoMillWorkOrder(tbl_sicomill_work_order data)
    {
        bool ret = false;
        BLL_tbl_sicomill_work_order bll = new BLL_tbl_sicomill_work_order();
        ret = bll.insert(data);

        return ret;
    }

    [WebMethod(true)]
    public static bool update_sicoMillWorkOrder(tbl_sicomill_work_order data)
    {
        bool ret = false;
        BLL_tbl_sicomill_work_order bll = new BLL_tbl_sicomill_work_order();
        ret = bll.update(data);

        return ret;
    }


    [WebMethod(true)]
    public static bool save_sicoMillProduction(tbl_sicomill_production data)
    {
        bool ret = false;
        BLL_tbl_sicomill_production bll = new BLL_tbl_sicomill_production();
        ret = bll.insert(data);

        return ret;
    }

    [WebMethod(true)]
    public static bool update_sicoMillProduction(tbl_sicomill_production data)
    {
        bool ret = false;
        BLL_tbl_sicomill_production bll = new BLL_tbl_sicomill_production();
        ret = bll.update(data);

        return ret;
    }


    [WebMethod(true)]
    public static bool save_sicoNideBlending(tbl_siconideblending data)
    {
        bool ret = false;
        BLL_tbl_siconideblending bll = new BLL_tbl_siconideblending();
        ret = bll.insert(data);
        
        return ret;
    }

    [WebMethod(true)]
    public static bool update_sicoNideBlending(tbl_siconideblending data)
    {
        bool ret = false;
        BLL_tbl_siconideblending bll = new BLL_tbl_siconideblending();
        ret = bll.update(data);

        return ret;
    }

    [WebMethod(true)]
    public static List<tbl_sicomill_inputvessels> getDrumNumberForxrf(string WorkOrderNumber)
    {
        List<tbl_sicomill_inputvessels> list = new List<tbl_sicomill_inputvessels>();
        DAL_tbl_sicomill_work_order dal = new DAL_tbl_sicomill_work_order();
        list = dal.ddlDrumNumber(WorkOrderNumber);
        return list;
    }

    [WebMethod(true)]
    public static List<tbl_qcsicomill_xrf> getDrumNumberForLecoCarbon(string WorkOrderNumber)
    {
        List<tbl_qcsicomill_xrf> list = new List<tbl_qcsicomill_xrf>();
        DAL_tbl_qcsicomill_xrf dal = new DAL_tbl_qcsicomill_xrf();
        list = dal.ddlDrumNumber(WorkOrderNumber);
        return list;
    }

    [WebMethod(true)]
    public static List<tbl_qcsicomill_leco_carbon> getDrumNumberForParticleSize(string WorkOrderNumber)
    {
        List<tbl_qcsicomill_leco_carbon> list = new List<tbl_qcsicomill_leco_carbon>();
        DAL_tbl_qcsicomill_leco_carbon dal = new DAL_tbl_qcsicomill_leco_carbon();
        list = dal.ddlDrumNumber(WorkOrderNumber);
        return list;
    }

    [WebMethod(true)]
    public static List<tbl_qcsicomill_particlesize> getDrumNumberForPH(string WorkOrderNumber)
    {
        List<tbl_qcsicomill_particlesize> list = new List<tbl_qcsicomill_particlesize>();
        DAL_tbl_qcsicomill_particlesize dal = new DAL_tbl_qcsicomill_particlesize();
        list = dal.ddlDrumNumber(WorkOrderNumber);
        return list;
    }

    [WebMethod(true)]
    public static List<tbl_qcsicomill_ph> getDrumNumberForSSA(string WorkOrderNumber)
    {
        List<tbl_qcsicomill_ph> list = new List<tbl_qcsicomill_ph>();
        DAL_tbl_qcsicomill_ph dal = new DAL_tbl_qcsicomill_ph();
        list = dal.ddlDrumNumber(WorkOrderNumber);
        return list;
    }

    [WebMethod(true)]
    public static List<tbl_qcsicomill_ssa> getDrumNumberFor635Mess(string WorkOrderNumber)
    {
        List<tbl_qcsicomill_ssa> list = new List<tbl_qcsicomill_ssa>();
        DAL_tbl_qcsicomill_ssa dal = new DAL_tbl_qcsicomill_ssa();
        list = dal.ddlDrumNumber(WorkOrderNumber);
        return list;
    }

    [WebMethod(true)]
    public static List<tbl_rm_receipt> getDrumNumber(string RMOrder)
    {
        List<tbl_rm_receipt> list = new List<tbl_rm_receipt>();
        DAL_tbl_rm_receipt dal = new DAL_tbl_rm_receipt();
        list = dal.ddlDrumNumber(RMOrder);
        return list;
    }

    [WebMethod(true)]
    public static List<tbl_rm_receipt> getBagNumber(string RMOrder)
    {
        List<tbl_rm_receipt> list = new List<tbl_rm_receipt>();
        DAL_tbl_rm_receipt dal = new DAL_tbl_rm_receipt();
        list = dal.ddlBagNumber(RMOrder);
        return list;
    }

    //public static string getWorkOrderNumber(string po)
    //{
    //    BLL_tbl_purchase_order bll = new BLL_tbl_purchase_order();
    //    DataTable dt = bll.getWorkOrderNum();
    //    if (dt != null)
    //    {
    //        DataRow[] dr = dt.Select("PO_ID='" + (ddlPO_Number.SelectedValue.ToString()).Trim() + "'");
    //        if (dr.Length > 0)
    //        {
    //            BLL_tbl_sicomill bllsicomill = new BLL_tbl_sicomill();
    //            DataTable dt1 = bllsicomill.getDateByPO_Number((ddlPO_Number.SelectedItem.ToString()).Trim());
    //            if (dt1.Rows.Count > 0)
    //            {
    //                string getworkorderNum = (dt1.Rows[0]["Work_Order_Numberr"].ToString()).Trim();
    //                string[] arr = getworkorderNum.Split('-');
    //                int lastNumber = Convert.ToInt32(arr[Convert.ToInt32(arr.Length) - 1]) + 1;
    //                txtWork_Order_Number.Text = DateTime.Now.ToString("yyMMdd") + "-" + dr[0]["user_code"].ToString() + "-" + Convert.ToInt32(lastNumber + 1);

    //            }
    //            else
    //            {
    //                txtWork_Order_Number.Text = DateTime.Now.ToString("yyMMdd") + "-" + dr[0]["user_code"].ToString() + "-" + "01";
    //            }
    //        }
    //    }  
    //}

    [WebMethod(true)]
    public static bool save_qc_RM(List<tbl_qc_rm> data)
    {
        bool ret = false;
        BLL_tbl_qc_rm bll = new BLL_tbl_qc_rm();
        ret = bll.insert(data);

        return ret;
    }

    [WebMethod(true)]
    public static bool update_qc_RM(List<tbl_qc_rm> data)
    {
        
        bool ret = false;
        //int ID = 20;
        BLL_tbl_qc_rm bll = new BLL_tbl_qc_rm();
        ret = bll.update(data);

        return ret;
    }

    [WebMethod]
    public static List<tbl_countrystatemapping> selectState(string country)
    {
        DAL_tbl_countrystatemapping dal = new DAL_tbl_countrystatemapping();
        return dal.selectState(country);
    }

    [WebMethod]
    public static List<tbl_countrystatemapping> selectCity(string country, string state)
    {
        DAL_tbl_countrystatemapping dal = new DAL_tbl_countrystatemapping();
        return dal.selectCity(country, state);
    }
}